//
//  MineEmptyTimeLineTableViewCell.swift
//  MT
//
//  Created by M on 2019/12/26.
//  Copyright © 2019 张强. All rights reserved.
//

import UIKit
import MTCategory

class MineEmptyTimelineTableViewCell: UITableViewCell {
    
    var isSelf: Bool = false {
        didSet {
            postButton.isHidden = !isSelf
        }
    }
    
    /// Icon
    lazy var emptyIconImageView: UIImageView = {
        let imgView = UIImageView()
        imgView.image = UIImage(named: "icon_empty")
        imgView.contentMode = .scaleAspectFill
        return imgView
    }()
    
    /// Label
    lazy var emptyLabel: UILabel = {
        let label = UILabel()
        label.text = "这里空空如也..."
        label.font = PingFangSCRegularFont(14)
        label.textColor = UIColor(hex: 0x5d5d5d)
        label.textAlignment = .center
        return label
    }()
    
    /// 发布按钮
    lazy var postButton: UIButton = {
        let btn = UIButton()
        btn.backgroundColor = UIColor.theme.main
        btn.setTitle("发布第一篇", for: .normal)
        btn.setTitleColor(UIColor.common.x161616, for: .normal)
        btn.titleLabel?.font = PingFangSCSemiboldFont(16)
        btn.adjustsImageWhenHighlighted = false
        btn.layer.cornerRadius = 22
        btn.addTarget(self, action: #selector(emptyTimelineCell(didClickPostButton:)), for: .touchUpInside)
        return btn
    }()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        initializeUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

// MARK: ------------------ Overrides ----------------------
extension MineEmptyTimelineTableViewCell {
    
    override func prepareForReuse() {
        super.prepareForReuse()
    }
    
}

// MARK: ------------------ 初始化 ----------------------
extension MineEmptyTimelineTableViewCell {
    
    private func initializeUI() {
        selectionStyle = .none
        contentView.backgroundColor = .black
        contentView.addSubview(emptyIconImageView)
        contentView.addSubview(emptyLabel)
        contentView.addSubview(postButton)
        
        emptyIconImageView.snp.makeConstraints { (make) in
            make.top.equalTo(contentView).offset(44)
            make.centerX.equalTo(contentView)
            make.width.equalTo(90)
            make.height.equalTo(85)
        }
        
        emptyLabel.snp.makeConstraints { (make) in
            make.top.equalTo(emptyIconImageView.snp.bottom).offset(10)
            make.centerX.equalTo(emptyIconImageView)
        }
        
        postButton.snp.makeConstraints { (make) in
            make.top.equalTo(emptyLabel.snp.bottom).offset(16)
            make.centerX.equalTo(emptyIconImageView)
            make.width.equalTo(210)
            make.height.equalTo(44)
        }
    }
    
}

// MARK: ------------------ 事件方法 ----------------------
@objc
extension MineEmptyTimelineTableViewCell {
    
    private func emptyTimelineCell(didClickPostButton sender: UIButton) {
        NotificationCenter.default.post(name: GlobalNotificationName.presentPostController.name, object: nil)
    }
    
}
